<script setup>
import OImage from "../setting/Images.vue";
import AlphaColor from "../setting/AlphaColor.vue";
import Editor from "../setting/Editor.vue";
import Slider from "../setting/Slider.vue";

const props = defineProps({
  config: {
    type: Object,
    required: true,
  },
  name: {
    type: String,
    default: "",
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});

const emits = defineEmits(["update:config", "change"]);

const form = ref({
  $position: { top: 0, left: 0 },
  $size: { width: 375, height: 50 },
  $removeable: true,
  $positionType: "relative",
  text: "这里是富文本的内容...",
  borderRadius: 0,
  bgShow: false,
  textPosition: { top: 10, left: 10 },
  textSize: { width: 345, height: 30 },
});

const typeList = [
  { label: "默认", key: "relative" },
  { label: "浮动", key: "absolute" },
];

const detail = computed({
  get: () => {
    return Object.assign({}, form.value, props.config);
  },
  set: (val) => {
    emits("update:config", val);
    emits("change", val);
  },
});

const changePositionType = () => {
  detail.value.$position = { left: 0, top: 0 };
  onChange();
};

const onChange = (val) => {
  detail.value = detail.value;
};

onMounted(() => {
  onChange();
});
</script>
<template>
  <el-form :model="detail" label-width="auto" :disabled="disabled">
    <el-form-item label="位置类型">
      <el-radio-group
        v-model="detail.$positionType"
        @change="changePositionType"
      >
        <el-radio v-for="item in typeList" :label="item.key">{{
          item.label
        }}</el-radio>
      </el-radio-group>
    </el-form-item>
    <AlphaColor v-model="detail.bgColor" name="背景色" @change="onChange" />
    <Slider
      v-model="detail.borderRadius"
      name="圆角"
      :max="20"
      @change="onChange"
    />
    <OImage
      v-model="detail.bg"
      v-model:size="detail.$size"
      v-model:show="detail.bgShow"
      name="背景图片"
      @change="onChange"
    />
    <Editor v-model="detail.text" name="富文本内容" @change="onChange" />
  </el-form>
</template>
